<?php
// $Id: template.block-editing.inc,v 1.2 2009/07/13 23:52:58 andregriffin Exp $

/**
 * Credit: John Albin Wilkins
 * @file
 * Contains functions only needed if the user has block editing permissions.
 */

/**
 * Add block editing variables into the block templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("block" in this case.)
 */
function framework_preprocess_block_editing(&$vars, $hook) {
  $block = $vars['block'];

  // Display 'edit block' for custom blocks.
  if ($block->module == 'block') {
    $edit_links[] = l('<span>' . t('[Edit Block]') . '</span>', 'admin/build/block/configure/' . $block->module . '/' . $block->delta,
      array(
        'attributes' => array(
          'title' => t('edit the content of this block'),
          'class' => 'block-edit',
        ),
        'query' => drupal_get_destination(),
        'html' => TRUE,
      )
    );
  }
  // Display 'configure' for other blocks.
  else {
    $edit_links[] = l('<span>' . t('[Configure]') . '</span>', 'admin/build/block/configure/' . $block->module . '/' . $block->delta,
      array(
        'attributes' => array(
          'title' => t('configure this block'),
          'class' => 'block-config',
        ),
        'query' => drupal_get_destination(),
        'html' => TRUE,
      )
    );
  }

  // Display 'edit view' for Views blocks.
  if ($block->module == 'views' && user_access('administer views')) {
    list($view_name, $view_block) = explode('-block', $block->delta);
    $edit_links[] = l('<span>' . t('[Edit View]') . '</span>', 'admin/build/views/edit/' . $view_name,
      array(
        'attributes' => array(
          'title' => t('edit the view that defines this block'),
          'class' => 'block-edit-view',
        ),
        'query' => drupal_get_destination(),
        'fragment' => 'views-tab-block' . $view_block,
        'html' => TRUE,
      )
    );
  }
  // Display 'edit menu' for Menu blocks.
  elseif (($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1)) && user_access('administer menu')) {
    $menu_name = ($block->module == 'user') ? 'navigation' : $block->delta;
    $edit_links[] = l('<span>' . t('[Edit Menu]') . '</span>', 'admin/build/menu-customize/' . $menu_name,
      array(
        'attributes' => array(
          'title' => t('edit the menu that defines this block'),
          'class' => 'block-edit-menu',
        ),
        'query' => drupal_get_destination(),
        'html' => TRUE,
      )
    );
  }

  // Display 'edit tabs' for QuickTabs blocks
  // added by najibx 
    elseif ($block->module == 'quicktabs') {
      $edit_links[] = l('<span>' . t('[Edit Tabs]') . '</span>', 'admin/build/' . $block->module . '/' . $block->delta . '/' . 'edit',
        array(
          'attributes' => array(
            'title' => t('Edit the tabs of this block.'),
            'class' => 'block-edit',
          ),
          'html' => TRUE,
        )
      );
    }

  // Display 'edit menu' for Menu block blocks.
  elseif ($block->module == 'menu_block' && user_access('administer menu')) {
    list($menu_name, ) = split(':', variable_get("menu_block_{$block->delta}_parent", 'navigation:0'));
    $edit_links[] = l('<span>' . t('[Edit Menu]') . '</span>', 'admin/build/menu-customize/' . $menu_name,
      array(
        'attributes' => array(
          'title' => t('edit the menu that defines this block'),
          'class' => 'block-edit-menu',
        ),
        'query' => drupal_get_destination(),
        'html' => TRUE,
      )
    );
  }

  $vars['edit_links_array'] = $edit_links;
  $vars['edit_links'] = '<div class="edit">' . implode(' ', $edit_links) . '</div>';
}
